#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/25 9:25
    Desc  :
--------------------------------------
"""
from flask import request
from functools import wraps

from common.libs.JsonResponseUtils import JsonResponse
from common.libs.JwtUtils import verify_jwt


def check_param(paramList: list):
    def view_decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            no_param = []
            form = {} if not request.json else dict(request.json)
            for i in paramList:
                if i not in list(form.keys()):
                    no_param.append(i)
            for i in list(form.keys()):
                if i == '':
                    no_param.append(i)
            if len(no_param) != 0:
                return JsonResponse(code = 40002, data = None, message = f"{','.join(no_param)}为必填项").jsonExit()
            return func(*args, **kwargs)

        return wrapper

    return view_decorator
